package com.cat.dynamicPlanning02;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/longest-square-streak-in-an-array/description/?envType=problem-list-v2&envId=Yvc80ctihttps://leetcode.cn/problems/longest-square-streak-in-an-array/description/?envType=problem-list-v2&envId=Yvc80cti
 * @create 2025/9/13 19:28
 * @since JDK17
 */

public class Solution07 {
    public int longestSquareStreak(int[] nums) {
        Arrays.sort(nums);
        int n = nums.length, ans = 0;
        HashMap<Double, Integer> map = new HashMap<>();
        map.put(nums[0] * 1.0, 1);
        for (int i = 1; i < n; i++) {
            int cnt = map.getOrDefault(Math.sqrt(nums[i]), 0) + 1;
            map.merge(nums[i] * 1.0, cnt, Integer::sum);
            ans = Math.max(cnt, ans);
        }

        return ans == 1 ? -1 : ans;
    }
}
